/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */






function attendenceLogin()
{
   var loginPostaVar={username:"parvez",password:"159357258456",action:"makeLoginLogout",requestedaction:"login"};
   var postUrl="http://172.16.0.3/oms/ocp/showDocument.php?documentid=45";

        ajaxRequest("post",postUrl ,loginPostaVar,function serverRsp(msg)
         {
                 //check for unclosed login
                 var rsp=0;
                 if(rsp==0)
                 {
                    //unclosed login  stuff    
                 }
                 else
                 {
                      MakePostRequest("http://172.16.0.3/oms/ocp/showDocument.php?documentid=45","");

                 }
                 //alert(msg);
         });

}


function unclosedLogin()
{
    if (subject.match(/days[\w\d\s;<\/>""=\-:.]+&[\w\s;<\/>""=\-:.,?]+[\D]+([0-9]+)/i)) {
    // Successful match
    } else {
// Match attempt failed
}

}




function ajaxresp(msg) {
    //$("#tbdetails").html(msg);
    //$("#data").html(msg);  
    //alert(msg);
    var name="parvez";
    var regExp=new RegExp(name+'[\\w\\d\\s&;<\\/>""=\\-:.]+\\?[a-zA-Z=]+[0-9]+[&a-zA-Z=;]+([0-9]+)[&a-zA-Z]+=login',"i");
    var output=msg.match(regExp);
    //var output= msg.match(/parvez[\w\d\s&;<\/>""=\-:.]+\?[a-zA-Z=]+[0-9]+[&a-zA-Z=;]+([0-9]+)[&a-zA-Z]+=login/i);
    alert(output[1]);
//var postData="username=parvez&password=159357258456&action=makeLoginLogout&requestedaction=logout&attendanceid="+output[1];
//var URI='http://172.16.0.3/oms/ocp/showDocument.php?documentid=45';
//MakePostRequest(URI,postData);
}

function ajaxRequest(type, url, serverdata, succfunc) {

    
    alert(serverdata.username);
    $.ajax({
        type: type,
        url: url,
        data: serverdata,
        success: succfunc,
        error: function(msg)
        {
            alert(msg);
        }
    });
}

var loginInfo={
    
    username:"",
    password:"",
    action:"",
    requestedaction:"",
    inoutid:"",
    inoutpurposeid:"",
    description:""
    
};

function foo(){
    alert("abc");
    window.openDialog("chrome://sample/content/mywindow.xul", "New Window", "width=600,height=300");


}
function showUrlinNewTab(url)
{
   window.openDialog("chrome://sample/content/UnclosedLoginTime.xul", "Last LogOutTime", "modal=yes,chrome=yes,centerscreen=yes")
   //alert(url);
    //gBrowser.selectedTab = gBrowser.addTab('http://172.16.0.3/oms/ocp/showDocument.php?documentid=45&#38;requestedaction=login&#38;formname=login');

    //alert(loginInfo.length);
    //ajaxRequest("get", "http://172.16.0.3/oms/ocp/showDocument.php?documentid=45","", ajaxresp);
    //Login Post data
    //    var postData="username=parvez&password=159357258456&action=makeLoginLogout&requestedaction=login";
    //    alert(postData);
    //    var URI='http://172.16.0.3/oms/ocp/showDocument.php?documentid=45';
    //var postData="username=parvez&password=159357258456&action=login";
    //alert(postData);
    //var URI='https://172.16.0.3/oms/ocp/showDocument.php?documentid=1';
    //     ajaxRequest("post", "https://172.16.0.3/oms/ocp/showDocument.php?documentid=1",{username:"parvez",password:"159357258456",action:"login"}, function serverRsp(msg)
    //     {
    //             alert(msg);
    //     });
    //    var URI='https://mail.commlinkinfotech.com/src/redirect.php';
    //    var postData="login_username=parvez&secretkey=12345678&js_autodetect_results=1";
    //    MakePostRequest(URI,postData);
    //loadURI('http://www.phpclasses.org/login.html?page=',REF,postData)
    //gBrowser.selectedTab = gBrowser.addTab('http://www.phpclasses.org/login.html?page=',REF,null,postData);

    //OpenExecutable("C:\\WINDOWS\\NOTEPAD.EXE");

    //getPreference ("myname");
}

function MakePostRequest(url,data)
{
    //var dataString="alias=pmtamal&password=12345678&dologin=1&user_name=pmtamal";
    var dataString=data;
    //var dataString = "alias=pmtamal&password=12345678&dologin=1&user_name=pmtamal";
    const REF_URI = Components.Constructor("@mozilla.org/network/standard-url;1", "nsIURI");
    var REF = new REF_URI;
    // POST method requests must wrap the encoded text in a MIME  stream
    const Cc = Components.classes;
    const Ci = Components.interfaces;
    var stringStream = Cc["@mozilla.org/io/string-input-stream;1"].
    createInstance(Ci.nsIStringInputStream);
    if ("data" in stringStream) // Gecko 1.9 or newer
        stringStream.data = dataString;
    else // 1.8 or older
        stringStream.setData(dataString, dataString.length);

    var postData = Cc["@mozilla.org/network/mime-input-stream;1"].
    createInstance(Ci.nsIMIMEInputStream);
    postData.addHeader("Content-Type", "application/x-www-form-urlencoded");
    postData.addContentLength = true;
    postData.setData(stringStream);
    gBrowser.selectedTab = gBrowser.addTab(url,REF,null,postData);
}

function OpenExecutable(path)
{
    alert(path);
    //netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
    var file = Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile);
    file.initWithPath(path);

    // create an nsIProcess
    var process = Components.classes["@mozilla.org/process/util;1"]
    .createInstance(Components.interfaces.nsIProcess);
    process.init(file);

    // Run the process.
    // If first param is true, calling thread will be blocked until
    // called process terminates.
    // Second and third params are used to pass command-line arguments
    // to the process.
    var args = ["argument1", "argument2"];
    process.run(true, null, null);

}

function getPreference(name)
{
    alert(name);
    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
    .getService(Components.interfaces.nsIPrefBranch);
    try{
        var temp=prefs.getCharPref("extensions.sample.defaultHomePage1"); // set a pref
        alert(temp);
    }
    catch(err)
    {
        alert(temp);
    }

//     prefs.setCharPref("extensions.sample.defaultHomePage", "www.yahoo.com"); // set a pref
//     temp=prefs.getCharPref("extensions.sample.defaultHomePage"); // set a pref
//     alert(temp);

}

function unClosedLogin()
{
    alert($('#time_Hour').val());
    alert("Start Unclosed Login");
}




